﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 简单了解Graphics操作;

namespace 简单了解Graphics操作
{
    enum Direction
    {
        UP,
        DOWN,
        LEFT,
        RIGHT
    }
    internal class Tank
    {
        //坦克的所有图片
        private Image[] _images = new Image[] {Resource1.p1tankU, Resource1.p1tankD, Resource1.p1tankL, Resource1.p1tankR};
        private int _speed;
        //坦克的X坐标
        public int X {  get; set; }
        //坦克的Y坐标
        public int Y { get; set; }
        //坦克的速度
        public int Speed { get => _speed; set => _speed = value; }
        //坦克的方向
        public Direction Direction { get; set; }
        
        public Tank(int x, int y, int speed, Direction direction)
        {
            X = x;
            Y = y;
            _speed = speed;
            Direction = direction;
        }

        //画坦克
        public void DrawTank(Graphics g)
        {
            switch (Direction)
            {
                case Direction.UP:
                    g.DrawImage(_images[0], new Point(X, Y));
                    break;
                case Direction.DOWN:
                    g.DrawImage(_images[1], new Point(X, Y));
                    break;
                case Direction.LEFT:
                    g.DrawImage(_images[2], new PointF(X, Y));
                    break;
                case Direction.RIGHT:
                    g.DrawImage(_images[3], new PointF(X, Y));
                    break;
            }
        }
        
        public void Move(Form form)
        {
            if(this.X <= this._speed)
            {
                this.X = this._speed;
            }
            if(this.Y <= this._speed)
            {
                this.Y = this._speed;
            }
            if(this.X > form.Width - 86)
            {
                this.X = form.Width - 86;
            }
            if(this.Y > form.Height - 108)
            {
                this.Y = form.Height - 108;
            }
            switch(Direction)
            {
                case Direction.UP:
                    this.Y -= _speed;
                    break;
                case Direction.DOWN:
                    this.Y += _speed;
                    break;
                case Direction.LEFT:
                    this.X -= _speed;
                    break;
                case Direction.RIGHT:
                    this.X += _speed;
                    break;
            }
        }
    }
}
